package heima.test.demo1;

import java.util.*;

public class DoubleColorBall {
    private Set<Integer> redBalls = new TreeSet<>();
    private int blueBall;

    public Set<Integer> getRedBalls() {
        return redBalls;
    }

    public void setRedBalls(Set<Integer> redBalls) {
        this.redBalls = redBalls;
    }

    public int getBlueBall() {
        return blueBall;
    }

    public void setBlueBall(int blueBall) {
        this.blueBall = blueBall;
    }

    public DoubleColorBall(){
        /*随机双色球号码*/
        Random random = new Random();
        while(redBalls.size() < 6){
            int num = random.nextInt(1, 36);
            redBalls.add(num);
        }
        blueBall = random.nextInt(1, 16);
    }

    public DoubleColorBall(List<Integer> redBalls, int blueBall){
        this.redBalls.addAll(redBalls);
        this.blueBall = blueBall;
    }

    public String toString(){
        return "红色：" + this.redBalls.toString() + "， 蓝色：" + this.blueBall;
    }

    public void compareWith(DoubleColorBall b){
        int red_num = 0;
        for(Integer ball : b.getRedBalls()){
            if(this.redBalls.contains(ball)){
                red_num += 1;
            }
        }
        int blue_num = 0;
        if(b.getBlueBall() == this.getBlueBall()){
            blue_num += 1;
        }
        System.out.println(red_num+"个红球相同，" + blue_num+"个蓝球相同");
    }


    public static void main(String[] args){
        DoubleColorBall b1 = new DoubleColorBall();
        DoubleColorBall b2 = new DoubleColorBall(Arrays.asList(10, 12, 30, 16, 7, 17), 12);
        System.out.println("随机双色球："+b1.toString());
        System.out.println("中奖双色球："+b2.toString());
        b1.compareWith(b2);
    }
}
